package com.custom.custapi.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.custom.custapi.pojo.SuperBaseEntity;
import com.custom.custapi.pojo.SuperBaseFilter;
import com.custom.custapi.pojo.SuperBasePager;
import org.apache.ibatis.annotations.Param;
import org.springframework.context.ApplicationContextAware;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @author zl
 * @version 1.0
 * @description 超级Mapper
 * @date 2025/1/1 1:1
 */
public interface SuperMapper extends ApplicationContextAware  {
    /**
     * 默认批次提交数量
     */
    int DEFAULT_BATCH_SIZE = 1000;

    <T extends SuperBaseEntity, R, F extends SuperBaseFilter> SuperBasePager<R> selectPage(F filter, Class<T> tClass);

    <T extends SuperBaseEntity> T selectById(Serializable id, Class<T> tClass);
    <T extends SuperBaseEntity> List<T> selectBatchIds(@Param(Constants.COLL) Collection<? extends Serializable> idList, Class<T> tClass);
    <T extends SuperBaseEntity> T selectOne(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);

    <T extends SuperBaseEntity> List<T> selectAll(Class<T> tClass);
    <T extends SuperBaseEntity> List<T> selectList(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
    <T extends SuperBaseEntity> List<Map<String, Object>> selectMaps(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);

    <T extends SuperBaseEntity> Long selectCount(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
    default <T extends SuperBaseEntity> boolean exists(Wrapper<T> queryWrapper) {
        Long count = this.selectCount(queryWrapper);
        return null != count && count > 0;
    }

    <T extends SuperBaseEntity> int insert(@Param(Constants.ENTITY) T entity);
    <T extends SuperBaseEntity> void insertList(Collection<T> dataList);

    <T extends SuperBaseEntity> int update(@Param(Constants.ENTITY) T entity, @Param(Constants.WRAPPER) Wrapper<T> updateWrapper);
    <T extends SuperBaseEntity> int updateById(@Param(Constants.ENTITY) T entity);
    <T extends SuperBaseEntity> void updateList(Collection<T> dataList);

    <T extends SuperBaseEntity> int delete(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
    <T extends SuperBaseEntity> int deleteById(T entity);
    <T extends SuperBaseEntity> int deleteById(Serializable id, Class<T> tClass);
//    <T extends CustBaseEntity> int deleteByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);
    <T extends SuperBaseEntity> int deleteBatchIds(@Param(Constants.COLL) Collection<?> idList, Class<T> tClass);

}
